<?php

require 'Model.php';
class VideoModel extends Model{

    function getVideoList(){
        $sql="select * from videos";
        $data=$this->conn->query($sql);
        return $data;
    }
    function delVideo($vid){
        $sql="delete from videos where vid=$vid";
        $result=$this->conn->query($sql);
        return $result;
    }
    function getTypeList(){
        $sql="select * from videotype";
        $datatype=$this->conn->query($sql);
        return $datatype;
    }
    function getVideoType($tid){
        $sql="select * from videotype where tid=$tid";
        $datatname=$this->conn->query($sql);
        return $datatname;

    }
    function regVideo($videoname, $videodegree,$gender,$birthdate,$graduatedate,$hobby,$school,$intro,$pic,$adress,$uploadtime,$uploadadmin,$hittimes,$downtimes){
        if($_FILES["img"]["error"]>0)
        {
            switch ($_FILES["img"]["error"]) {
                case 1:echo "文件上传过大";
                    break;
                case 3:echo "文件上传失败";
                    break;
                case 4:echo "没有文件上传";

                    $sql="insert into videos values(null,'$videoname','$videodegree','$gender', '$birthdate', '$graduatedate','$hobby','$school','$intro',null,'$uploadtime','$uploadadmin','$hittimes','$downtimes','$adress')";

                    break;
                default:echo "未知错误"; exit;

            }
        }
        else
        {  //上传文件}
            echo $_FILES["img"]["name"];
            $uploadpic=$_FILES["img"]["name"];
            $filepath="./posters/";
            $newname=$this->upload($uploadpic,$filepath);

            $sql="insert into videos values(null,'$videoname','$videodegree','$gender', '$birthdate', '$graduatedate','$hobby','$school','$intro','$newname','$uploadtime','$uploadadmin','$hittimes','$downtimes','$adress')";
        }
        //echo $sql;
        $result=$this->conn->query($sql);
        return $result;
    }

    function getVideo($vid){
        $sql="select * from videos where vid=$vid";
        $data=$this->conn->query($sql);
        return $data;
    }
  function editVideo($vid, $videoname, $videodegree, $gender, $birthdate, $graduatedate, $hobby, $school, $intro, $pic){
      if($_FILES["img"]["error"]>0)
      {
          switch ($_FILES["img"]["error"]) {
              case 1:echo "文件上传过大";
                  break;
              case 3:echo "文件上传失败";
                  break;
              case 4:echo "没有文件上传";

                  $sql="update videos set  videoname='{$videoname}',tid='{$videodegree}',gender='{$gender}',birthdate='{$birthdate}',graduatedate='{$graduatedate}',hobby='{$hobby}',school='{$school}',intro='{$intro}'where vid={$vid}";

                  break;
              default:echo "未知错误"; exit;

          }
      }
      else
      {  //上传文件
          echo $_FILES["img"]["name"];
          $uploadpic=$_FILES["img"]["name"];
          $filepath="./posters/";
          $newname=$this->upload($uploadpic,$filepath);

          $sql="update videos set  videoname='{$videoname}', tid='{$videodegree}',gender='{$gender}',birthdate='{$birthdate}',graduatedate='{$graduatedate}',hobby='{$hobby}',school='{$school}',pic='{$newname}',intro='{$intro}'where vid={$vid}";
      }
      $result=$this->conn->query($sql);
      return $result;
  }

}
?>